package com.example.viewtest.AdapterGroup;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.viewtest.Dao.Bean;
import com.example.viewtest.R;

import java.util.List;

public class ListViewAdapter extends BaseAdapter {

    private List<Bean> data;
    private Context context;

    public ListViewAdapter(List<Bean> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        //convertView是一个View视图缓存，底层会通过算法计算在缓存中找出当前要使用的那个view
        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.listview_item,viewGroup,false);
            Log.d("ListView","创建视图-----："+position);
        }//疑似多余操作，convertView缓存的视图和将其赋值给view的视图相同，直接使用缓存和使用view本质完全相同
        TextView textView = convertView.findViewById(R.id.listView_item_1);
        textView.setText(data.get(position).getName());
        Log.d("Create View","getView-----: " + position);
        return convertView;
    }
}
